class Solution {
public:
    void setZeroes(vector<vector<int>>& matrix) {
        queue<pair<int, int>> que;
        int m = matrix.size(), n = matrix[0].size();

        for (int i = 0; i < m; i++) {
            for (int j = 0; j < n; j++) {
                if (matrix[i][j] == 0)
                    que.push({ i, j });
            }
        }
        while (que.size()) {
            auto [a, b] = que.front();
            que.pop();

            for (int i = 0; i < m; i++)
                matrix[i][b] = 0;

            for (int i = 0; i < n; i++)
                matrix[a][i] = 0;
        }
    }
};